/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ranch.api.service;

import java.io.InputStream;
import java.util.List;
import org.ranch.model.Address;
import org.ranch.model.Animal;
import org.ranch.model.Farm;
import org.ranch.model.Kraal;
import org.ranch.model.Person;
import org.ranch.model.exception.RanchValidationException;

/**
 * Handles the CRUD operations for an animal (insert, delete, update, read)
 */
public interface FarmService {

     /**
     * Save the given animal
     *
     * @param animal
     * @throws RanchValidationException
     *             if the given animal has some invalid input
     */
    void save(Animal animal) throws RanchValidationException;

    /**
     * Deletes the given animal
     *
     * @param animal
     */
    void delete(Animal animal);

    /**
     * Retrieves an Animal with the corresponding ID from the DB
     *
     * @param id
     * @return
     */
    Animal getAnimalById(String id);

    /**
     * Retrieves a List of Animals from the DB
     *
     * @return
     */
    List<Animal> getAnimals();

    /**
     * Save the given kraal
     *
     * @param kraal
     */
    void save(Kraal kraal) throws RanchValidationException;

    /**
     * Deletes the given kraal
     *
     * @param kraal
     */
    void delete(Kraal Kraal);

    /**
     * Retrieves the Kraal with the corresponding ID from the DB
     *
     * @param id
     * @return
     */
    Kraal getKraalById(String id);

    /**
     * Retrieves a List of Kraals from the DB
     *
     * @return
     */
    List<Kraal> getKraals();

    /**
     * gets a list of Kraals in a given page
     *
     * @param pageNo
     * @return
     */
    List<Kraal> getKraalsByPage(Integer pageNo);

    /**
     * searches Kraal for those with matching title
     *
     * @param query
     * @return
     */
    List<Kraal> searchKraalsByTitle(String query);

    /**
     * searches Kraal based on the criteria and returns the required
     * page
     *
     * @param query
     * @param pageNumber
     * @return
     */
    List<Kraal> searchKraalsByTitle(String query, Integer pageNumber);

    /**
     * gets the total number of Kraal that meet a search criteria
     *
     * @return
     */
    int getNumberOfKraalsInSearch(String query, Integer pageNumber);

    /**
     * gets the total number of Kraal in the system
     *
     * @return
     */
    int getNumberOfKraals();

    /**
     * Save the given Farm
     *
     * @param farm
     */
    void save(Farm farm) throws RanchValidationException;

    /**
     * Deletes the given Farm
     *
     * @param farm
     */
    void delete(Farm Farm);

    /**
     * Retrieves the Farm with the corresponding ID from the DB
     *
     * @param id
     * @return
     */
    Farm getFarmById(String id);

    /**
     * Retrieves a List of Farms from the DB
     *
     * @return
     */
    List<Farm> getFarms();

    /**
     * purges a given Farm from the system. This completely removes the
     * Farms from the system
     *
     * @param concept
     */
    void purgeFarm(Farm farmr);

    /**
     * returns a list of farms in a given page and sorted by their ids.
     * The maximum number of records for a given page is determine by the
     * {@link org.ranch.api.RanchConstants.MAX_NUM_PAGE_RECORD} constant
     *
     * @param pageNo
     *            the page number to which to get the results - the page number
     *            starts from 1
     *
     * @return list of farms
     */
    List<Farm> getFarms(Integer pageNo);

    /**
     * deletes Farms whose ids are given in the list below.
     *
     * @param FarmIds
     */
    void deleteFarm(List<String> farmIds);

    /**
     *
     * @return
     */
    int getTotalNumberOfFarm();

    /**
     * gets a list of Farms that start with a given searchterm in their
     * name
     *
     * @param searchTerm
     * @return
     */

    List<Farm> getFarmThatStartWith(String searchTerm);
    
    /**
     * Save Animal.
     */
    
    void saveFarmAnimal(Farm farm, Animal animal) throws RanchValidationException;
    
    /**
     * saves the given farm kraal.
     *
     * @param kraal
     *            the farm kraal.
     * @return true if the operation was successfull without any errors.
     */
    boolean saveFarmKraal(Kraal kraal);

    /**
     * deletes the given farm kraal from the system
     *
     * @param kraal
     *            the farm kraal to delete
     * @return true if the operation was successful and false if otherwise.
     */
    boolean deleteFarmKraal(Kraal Kraal);

    /**
     * deletes a given person
     *
     * @param person
     */
    void deletePerson(Person person);

    /**
     * deletes a given list of persons
     *
     * @param person
     */
    void deletePersons(List<Person> persons);

    /**
     * saves the address of the given Farm.
     *
     * @param famr
     * @param address
     * @return
     */
    boolean saveFarmAddress(Farm staff, Address address) throws RanchValidationException;

    /**
     * @param query
     * @param pageNo
     * @return
     */
    List<Animal> searchAnimalByTagNo(String query);

    /**
     * @param query
     * @return
     */
    long getNumberOfAnimalsInSearch(String query);

    /**
     * Validating the farm object before saving
     * 
     * @param farm
     */
    void validateFarm(Farm farm) throws RanchValidationException;

    /**
     * Validating the kraal before saving
     * 
     * @param kraalOldModel
     */
    void validateKraal(Kraal kraal) throws RanchValidationException;

    /**
     *	Validating the animal object before saving
     * 
     * @param oldAnimal
     */
    void validateAnimal(Animal animal) throws RanchValidationException;

    /**
     * @param query
     * @param kraalid
     * @return
     */
    List<Animal> searchAnimalByTagNo(String query, String kraalid);

    /**
     * @param pageNo
     * @return
     */
    List<Animal> getAnimals(Integer pageNo);

    /**
     * @return
     */
    long getTotalNumberOfAnimal();

    /**
     * @param params
     * @param pageNo
     * @return
     */
    List<Animal> searchWithParams(AnimalSearchParameters params, Integer pageNo);

    /**
     * @param params
     * @return
     */
    long numberOfAnimalWithSearchParams(AnimalSearchParameters params);

    /**
     * @param params
     * @return
     */
    InputStream exportToExcel(AnimalSearchParameters params);
    
    /**
     * Get a specific animal using earTag
     * @param earTag
     * @return
     */
    Animal getAnimalByEarTag(String earTag);
    
    Kraal getKraalByName(String name);
}
